﻿using System;
using BusinessLogic;
using Contracts;
using DreamDriven.SoftwareFactory.Common;

namespace Presentation
{
    /// <summary>
    /// Presenter for <see cref="IDataObjectView"/>
    /// </summary>
    public sealed class DataObjectPresenter : Presenter<IDataObjectView>
    {
        /// <summary>
        /// Gets the business logic manager.
        /// It provides operations under business logic of Domain Model.
        /// It registered in Domain Model constructor.
        /// </summary>
        /// <value>The business logic manager.</value>
        private BusinessLogicManager BusinessLogicManager
        {
            get { return GetDomainModel<DomainModel>().BusinessLogicManager; }
        }

        /// <summary>
        /// Gets the service.
        /// Service registred with Domain Model and represents a contract of Domain Model.
        /// Possibly to invoke different services that registered in application configuration file.
        /// For this you should to add reference to Service contract.
        /// </summary>
        /// <value>The service.</value>
        private IService Service
        {
            get { return GetService<IService>(); }
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="DataObjectPresenter"/> class.
        /// </summary>
        /// <param name="view">The view.</param>
        public DataObjectPresenter(IDataObjectView view)
            : base(view)
        {
            View.Load += OnViewLoad;
        }

        private void OnViewLoad(object sender, EventArgs e)
        {
            View.Name = "Hello, DreamDriven.NET!";
            
            //Different ways to invoke method DoSomething.
            BusinessLogicManager.DoSomething();
            //In other Domain Models you can invoke this method throuth Service only.
            Service.DoSomething();
        }

        public override void ReleaseView()
        {
            View.Load -= OnViewLoad;
        }
    }
}
